import config from './utils/config'
import sitemap from './utils/sitemap';

export default {
  server: {
    port: 3000,
    // host: '0.0.0.0'
  },
  // Global page headers: https://go.nuxtjs.dev/config-head
  head: {
    title: 'Simple社区-Python开发者社区',
    htmlAttrs: {
      lang: 'zh-CN'
    },
    meta: [
      {charset: 'utf-8'},
      {name: 'viewport', content: 'width=device-width, initial-scale=1'},
      {hid: 'description', name: 'description', content: ''},
      {name: 'format-detection', content: 'telephone=no'}
    ],
    link: [
      {rel: 'icon', type: 'image/x-icon', href: '/favicon.ico'}
    ]
  },

  // Global CSS: https://go.nuxtjs.dev/config-css
  css: [
    'element-ui/lib/theme-chalk/index.css',
    '~/static/css/normalize.css',
    '~/static/css/global.css',
    '~/static/css/markdown.css'
  ],

  // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
  plugins: [
    '@/plugins/element-ui',
    '@/plugins/authorization',
    {src: '~plugins/mavon-editor', ssr: false},
  ],

  // Auto import components: https://go.nuxtjs.dev/config-components
  components: true,

  // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
  buildModules: [],

  // Modules: https://go.nuxtjs.dev/config-modules
  modules: [
    '@nuxtjs/proxy',
    '@nuxtjs/sitemap'
  ],

  // Build Configuration: https://go.nuxtjs.dev/config-build
  build: {
    transpile: [/^element-ui/],
    //css提取成单独的文件
    extractCSS: {
      allChunks: true
    },
    optimization: {
      splitChunks: {
        cacheGroups: {
          styles: {
            name: 'styles',
            test: /\.css$/,
            chunks: 'all',
            enforce: true
          }
        }
      }
    }
  },
  router: {

    //自定义路由
    extendRoutes(router, resolve) {

      //首页
      router.push({
        name: 'index-page',
        path: '/page/:page?',
        component: resolve(__dirname, 'pages/index.vue')
      });

      //分类
      router.push({
        name: 'node',
        path: '/node/:id',
        component: resolve(__dirname, 'pages/index.vue')
      });

      //分类分页
      router.push({
        name: 'node-page',
        path: '/node/:id/page/:page',
        component: resolve(__dirname, 'pages/index.vue')
      });

      //搜索页
      router.push({
        name: 'search-key',
        path: '/search/:q',
        component: resolve(__dirname, 'pages/search.vue')
      });

      //个人帖子分页
      router.push({
        name: 'profile-posts',
        path: '/profile/:id/posts/:page',
        component: resolve(__dirname, 'pages/profile/_id.vue')
      });

      //回复的
      router.push({
        name: 'profile-comments',
        path: '/profile/:id/comments/:page',
        component: resolve(__dirname, 'pages/profile/_id.vue')
      });

      //个人资料
      router.push({
        name: 'my-settings',
        path: '/my/settings',
        component: resolve(__dirname, 'pages/profile/_id.vue')
      });

      //订单
      router.push({
        name: 'my-order',
        path: '/my/order',
        component: resolve(__dirname, 'pages/profile/_id.vue')
      });

      //邀请回答
      router.push({
        name: 'my-invitation',
        path: '/my/invitation',
        component: resolve(__dirname, 'pages/profile/_id.vue')
      })
      //编辑帖子
      router.push({
        name: 'topic-edit',
        path: '/topic/edit/:id',
        component: resolve(__dirname, 'pages/post/topic.vue')
      });

      //向某个人提问
      router.push({
        name: 'ask-to',
        path: '/ask/to/:userId',
        component: resolve(__dirname, 'pages/post/topic.vue')
      });

      router.push({
        name: 'simplerpo-faq',
        path: '/simplerpo/faq',
        component: resolve(__dirname, 'pages/faqPage.vue')
      })
    }
  },
  proxy: {
    '/media': {
      target: config.api.proxy,
      sceure: false
    },
    '/api': {
      target: config.api.baseUrl
    }
  },
  sitemap: sitemap
}
